home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / midi / midifl12.lha / midifile.new / mfwrite_ex.c < prev    next >
C/C++ Source or Header  |  1995-08-27  |  2KB  |  76 lines

  1. /*
  2.  * writing_example.c 4/30/89
  3.  *
  4.  */
  5. #include <stdio.h>
  6. #include <ctype.h>
  7. #include "midifile.h"
  8.  
  9. /* These lines are needed to use the library */
  10. FILE *fp;
  11. /* myputc : returns <int> with input variables:
  12.  * c:
  13.  */
  14. int myputc (char c)
  15. {
  16.   return (putc (c, fp));
  17. }
  18.  
  19. /* ------------------------------------------------------------------------ */
  20.  
  21.  
  22. /*
  23.  * mywritetrack()
  24.  *
  25.  * Sample showing how to use the library routines to write out a track.
  26.  * Returns 1 if successful, and -1 if not.  The track consists of
  27.  * a series of quarter notes from lowest to highest in pitch at
  28.  * constant velocity, each separted by a quarter-note rest.
  29.  *
  30.  */
  31. /* mywritetrack : returns <int> with input variables:
  32.  * track:
  33.  */
  34. int mywritetrack (int track)
  35. {
  36.   int i;
  37.   char data[2];
  38.  
  39.   mf_write_tempo ((long) 500000);    /* 120 beats/per/second */
  40.  
  41.   for (i = 1; i < 128; i++) {
  42.  
  43.     data[0] = i;        /* note number */
  44.     data[1] = 64;        /* velocity */
  45.     if (!mf_write_midi_event (480, note_on, 1, data, 2))
  46.     return (-1);
  47.     if (!mf_write_midi_event (480, note_off, 1, data, 2))
  48.     return (-1);
  49.     }
  50.   return (1);
  51. }
  52.  
  53. /* ------------------------------------------------------------------------ */
  54.  
  55. /* end of write_track() */
  56. /* main : returns <int> with input variables:
  57.  * argc:
  58.  * argv:
  59.  */
  60. int main (
  61.   int argc,
  62.   char **argv)
  63. {
  64.   if ((fp = fopen (argv[1], "w")) == 0L)
  65. printf ("f1to0: unable to open file %s for writing.\n", argv[1]);
  66.  
  67.   Mf_putc = myputc;
  68.   Mf_writetrack = mywritetrack;
  69.  
  70.   /* write a single track */
  71.   mfwrite (0, 1, 480, fp);
  72. }
  73.  
  74. /* ------------------------------------------------------------------------ */
  75.  
  76.